import { observer } from "../../reactive/observe.js";

export default function initData(vm) {
    let _data
    if (typeof vm.$data == "object") {
        _data = vm._data = vm.$data;
    }
    if (typeof vm.$data == "function") {
        _data = vm._data = vm.$data();
    }
    for (let key in _data) {
        proxy(vm, "_data", key)
    }
    observer(_data);
}
 /* 在vm代理一层属性 */
function proxy(vm, data, key) {
    Object.defineProperty(vm, key, {
        get() {
            return vm[data][key]
        },
        set(newVal) {
            vm[data][key] = newVal
        }
    })
}
